package com.hantang.web.json.handlers;

import org.glassfish.grizzly.http.server.Request;
import org.glassfish.grizzly.http.server.Response;

import com.google.gson.Gson;
import com.hantang.web.dao.NewMessageDao;
import com.hantang.web.json.ds.MetaData;
import com.hantang.web.json.res.StringRes;

public class DeleteNews extends AbstractHandler {

	@Override
	public String doService(Request req, Response resp) throws Exception {
		
		String sid = req.getParameter("id");
		
		String sret = handleServlet(sid);
		return sret;
	}

	public static String handleServlet(String sid) {
		StringRes sres = new StringRes();
		
		if(sid!=null){
			long id = Long.valueOf(sid.trim());
			NewMessageDao dao = new NewMessageDao();
			boolean isOK = dao.deleteData(id);
			if(isOK){
				sres.setData(""+ sid);
				sres.setMeta(new MetaData(MetaData.META_DATA_SUCCESS_CODE, "Succ"));				
			}else{
				sres.setMeta(new MetaData(MetaData.META_DATA_FAILED_CODE, "Failed"));
			}
		}else{
			sres.setMeta(new MetaData(MetaData.META_DATA_ERROR_PARA, "need para id!"));
		}
		
		Gson gson = new Gson();
		String sret=  gson.toJson(sres);
		return sret;
	}

}
